package com.caicai.springbootrocketmq.product;

import com.caicai.springbootrocketmq.product.transaction.TransactionListenerImpl;
import org.apache.rocketmq.client.producer.TransactionListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 生产者配置
 *
 * @author: 菜菜的后端私房菜
 * @create: 2024/8/21 15:41
 * @description:
 */
@Configuration
public class ProductConfig {

    @Value("${rocketmq.name-server}")
    private String nameServer;

    @Value("${rocketmq.producer.group}")
    private String producerGroup;

    /**
     * 实例化生产者
     * @return
     */
    @Bean
    public ServerProduct serverProduct() {
        System.out.println("producerGroup:" + producerGroup);
        System.out.println("nameServer:" + nameServer);
        return new ServerProduct(producerGroup, nameServer);
    }

    @Bean
    public ServerTransactionProduct serverTransactionProduct() {
        return new ServerTransactionProduct(transactionListener(), "Default_Server_Transaction_Producer_Group", nameServer);
    }

    @Bean
    public TransactionListener transactionListener() {
        return new TransactionListenerImpl();
    }
}
